<%@page contentType="text/html; charset=utf-8" %>
<%@ include file="/commons/taglibs.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>选 择</title>
<link href="${ctx}/styles/listTable.css" rel="stylesheet" type="text/css">
<link href="${ctx}/styles/aux_window.css" rel="stylesheet" type="text/css">
<link href="${ctx}/styles/mainmenu2.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/public.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/div/common.js"></script>

<script type="text/javascript">
	var multiHouseobj = null;
	function MultiHouseObject(mainTableId){
		this.mainTableList = document.getElementById(mainTableId);

		this.houseCache = null;
		/****添加一个元素*****/
		this.addElement = function(houseId,houseNumber){
			buildHouseTr(this.mainTableList,houseId,houseNumber);
		}
		/********删除一个元素********/
		this.deleteElement = function(objTd){
			this.mainTableList.deleteRow(objTd.parentNode.rowIndex);
			window.frames('houseListFrame').changeTd(objTd.id);
		}
		/*********获取所选择的房屋信息**********/
		this.getHouseInfo = function(){
			var houseArray = new Array();
			var jsonStr = "";
			var cells = this.mainTableList.cells;
			for(i = 0; i < cells.length; i++){
				jsonStr += "{'houseId':'" + cells[i].id + "'";
				jsonStr += ",'houseNumber':'" + cells[i].innerText + "'";
				jsonStr += "}";
				houseArray[houseArray.length] = eval("(" + jsonStr + ")");
				jsonStr = "";
			}

			return houseArray;
		}

/************************私有方法**********************************/
		/*****给指定的table添加一行*****/
		function buildHouseTr(objTable,id,innerText){
			var newRow = objTable.insertRow();
			var newCell = newRow.insertCell();
			newCell.id = id;
			newCell.innerHTML = innerText;
			newCell.appendChild(buildDeleteImage());
		}
		/*****私有方法：创建删除的图片******/
		function buildDeleteImage(id){
			var objImg = document.createElement("img");
			objImg.id = id + "_img"
			objImg.src = "${ctx}/images/ico_delete.gif";
			objImg.onclick = function(){
				multiHouseobj.deleteElement(objImg.parentNode);
			}
			return objImg;
		}
	}
	/***重新刷新列表****/
	function reloadIframe(thiz){
		var selectId = thiz.value
		document.all.houseListFrame.src = "${ctx}/common_commonAction.do?method=chooseMultiHouseWithBuildList&selectId=" + selectId;
	}

	function saveHouseInfo(){
		var houseInfo =  multiHouseobj.getHouseInfo();
		var parentFrame = ${not empty parentFrame} ? "${parentFrame}" : "houseChooses";
		var obj = findFrame(parentFrame);
		obj.setHouseInfo(houseInfo);
		windowClose();
	}

	function addAll(){
		document.frames['houseListFrame'].addAll();
		//$('houseListFrame').addAll();
	}

	function init(){
		multiHouseobj = new MultiHouseObject('mainSelectedTable');
	}
</script>
</head>

<body onload="init();">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="outtable">
  <tr>
    <td class="window_head_outBg"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><span class="window_head_intext"><img src="${ctx}/images/ico_Advance.gif" align="absmiddle">&nbsp;增加房间</span></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td class="aux_header_line_1"></td>
  </tr>
  <tr>
    <td class="aux_header_line_2"></td>
  </tr>
  <tr>
    <td class="content">
      <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="outtable">
        <tr>
          <td>
          	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	            <tr>
	              <td>
	                <table width="100%" border="0" cellspacing="0" cellpadding="0">
	                  <tr>
<td class="aux_outtable_color">
                  		<table width="100%" border="0" cellspacing="0" cellpadding="0">
                  			<tr>
                  				<td>
                  					<table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">
                  						<tr>
                  							<td colspan="2" class="aux_intable_td1">
                  								<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="outtable">
                  									<tr>
                  										 <td  valign="top">
															<div class="leftTree" >
                  										 		<table width="100%" border="0" cellspacing="0" cellpadding="0">
                  										 			<tr>
                  										 				<td height="24">
                  										 					<table width="100%" border="0" cellspacing="0" cellpadding="0">
                  										 						<tr>
                  										 							<td height="24">&nbsp;&nbsp;已选择的列表：</td>
                  										 						</tr>
                  										 					</table>
                  										 				</td>
                  										 			</tr>
                  										 			<tr>
													                    <td>
													                    	<table  width="100%" height="100" border="0" cellpadding="0" cellspacing="1">
													                        <tr>
													                          <td align="left" valign="top" nowrap class="LeftdownBlock1" style="padding:3px;"><div style="OVERFLOW: auto; WIDTH: 100%;  HEIGHT: 100%">
													                              <table id="mainSelectedTable" border="1" cellspacing="3" cellpadding="0" id="table1" class="lastselect"  style="border-collapse:collapse" bordercolor="BCBFD2" >
													                              </table>
													                          </div></td>
													                        </tr>
													                    </table></td>
                  										 			</tr>
                  										 		</table>
                  										 	</div>
															  &nbsp;
															  <div class="leftTree"  >
														      	<table width="100%" border="0" cellspacing="0" cellpadding="0">
														        	<tr>
														          		<td height="25" width="25%">
														          			<table width="100%" border="0" cellspacing="0" cellpadding="0">
														            			<tr>
														              				<td>&nbsp;&nbsp;楼栋单元：
																			              <pms:unitedSelect name="selectMenu"
																			              					dataList="${buildingList}"
																			              					optionLabel="selectText"
																			              					optionValue="selectId"
																			              					onChange="reloadIframe(this);"
																			              					selectText="请选择...">
																			              </pms:unitedSelect>
														                			</td>
														            			</tr>
														          			</table>
														          		</td>
								          								<td width="75%">
																		<table border="0" cellpadding="0" cellspacing="0" id="ico1">
																			<tr>
																				<td class="toolbarico" id="tdSelectAll" onclick="addAll()" ><a href="javascript:void(0)"><img
																					src="${ctx}/images/ico_xf.gif" border="0" align="absbottom"
																					 /> 选择全部</a></td>
																			</tr>
																		</table>
																		</td>
														        	</tr>
														        	<tr>
														          <td colspan="2">
														            <table width="100%" height="200" border="0" cellpadding="0" cellspacing="1" >
														              <tr>
														                <td  align="left" valign="top" nowrap class="LeftdownBlock1" style="padding-top:3px;">
														                	<iframe id="houseListFrame" name="houseListFrame" src="${ctx}/common_commonAction.do?method=chooseMultiHouseWithBuildList" width="100%" frameborder="0" height="260"></iframe>
														                </td>
														              </tr>
														            </table>
														          </td>
														        </tr>
														      </table>
														      </div>
                  										 </td>
                  									</tr>
                  								</table>
                  							</td>
                  						</tr>
                  					</table>
                  				</td>
                  			</tr>
						</table>
					 </td>
	                  </tr>
	                </table>
	               </td>
	            </tr>
          	</table>
          </td>
        </tr>
      </table>
      </td>
  </tr>
  <tr>
    <td colspan="2" class="window_footer">      <table border="0" cellspacing="0" cellpadding="0">
        <tr>
		  <td><table border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td class="buttonOffLeft" id="btn1_21"></td>
                <td class="buttonOffMiddle" id="btn1_22" onClick="saveHouseInfo();" onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)" onBlur="btn_change(2)"><img src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14" border="0" align="absbottom"> 确 定</td>
                <td class="buttonOffRight" id="btn1_23"></td>
              </tr>
          </table></td>
          <td class="btn_between_space"></td>
          <td><table border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td class="buttonOffLeft" id="btn1_31"></td>
                <td class="buttonOffMiddle" id="btn1_32" onClick="windowClose();" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)" onBlur="btn_change(3)"><img src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14" border="0" align="absbottom"> 取 消</td>
                <td class="buttonOffRight" id="btn1_33"></td>
              </tr>
          </table></td>
        </tr>
          </table>
      <p>&nbsp;</p></td>
  </tr>
</table>

</body>
</html>
